package models;

import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import ch.bfh.abcm.rems.sensors.tinkerforge.TFSensorType;
import play.db.jpa.Model;

@Entity
public class CNAverage extends Model{

    private long timestamp;
    private int value;
    private String clusterNodeID;
    
    @OneToOne
    private TFSensorType sensorType;
    
    protected CNAverage(){}
    
    public CNAverage(int value, String clusterNodeID, TFSensorType sensorType){
        this.clusterNodeID = clusterNodeID;
        this.value = value;
        this.sensorType = sensorType;
        this.timestamp = new Date().getTime();
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getClusterNodeID() {
        return clusterNodeID;
    }

    public void setClusterNodeID(String clusterNodeID) {
        this.clusterNodeID = clusterNodeID;
    }

    public TFSensorType getSensorType() {
        return sensorType;
    }

    public void setSensorType(TFSensorType sensorType) {
        this.sensorType = sensorType;
    }
    
    public static CNAverage saveCNAverage(int value, String clusterNodeID, TFSensorType sensorType) {
        CNAverage data = new CNAverage(value, clusterNodeID, sensorType);
        data.save();
        return data;
    }
    
    public String toString() {
        return "SensorData: {Timestamp=" + new Timestamp(timestamp) + " value="+value+" CNID=" + clusterNodeID + "}";
    }
}
